package a06;

import org.springframework.beans.BeansException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.config.BeanFactoryPostProcessor;
import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.context.annotation.Bean;

public class MyConfig2 implements ApplicationContextAware {


    /**
     * @Autowire会失效，使用Aware注入就不会失效呢
     */
    @Override
    public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
        System.out.println("*******Aware方法，applicationContext: " + applicationContext);
    }


    /**
     * 会导致上面的@Autowired失效
     * @return
     */
    @Bean
    public BeanFactoryPostProcessor processor1() {
        return new BeanFactoryPostProcessor() {
            @Override
            public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) throws BeansException {
                System.out.println("自定义后置处理器....");
            }
        };
    }


}
